package com.crm.system.controller.csd.customerManager;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.csd.customerManager.CustomerServiceWorkLogQO;
import com.crm.model.vo.csd.customerManager.CustomerServiceWorkLogVO;
import com.crm.system.service.csd.customerManager.CustomerServiceWorkLogService;
import com.crm.system.service.impl.csd.customerManager.CustomerServiceWorkLogServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author yincuimei
 * @Date 2021/8/23 9:15
 */
@RestController
@RequestMapping("/csd/workLog")
public class CustomerServiceWorkLogController {

    @Autowired
    private CustomerServiceWorkLogService workLogService;

    /**
     * (客服部)日志列表
     * @author yincuimei
     * @return
     */
    @PostMapping("/selectWorkLogList")
    public DataResponse selectCustomerList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                           @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                           @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                           @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                           String customerId//查询条件
    ){
        try{
            DhPageInfo<CustomerServiceWorkLogVO> workLogVODhPageInfo = workLogService.selectWorkLogList(customerId,pageIndex,pageSize,sortName,sortOrder);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogVODhPageInfo);
        }catch(Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * (客服部)工作日志--查看
     * @param workLogId   --日志主键
     * @author yincuimei
     * @return
     */
    @PostMapping("/selectWorkLogById")
    public DataResponse selectWorkLogById(@RequestParam(value = "workLogId", required = true) String workLogId){
        try{
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),workLogService.selectWorkLogById(workLogId));
        }catch (Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * (客服部)工作日志--备注(修改备注、上传附件)
     * @return
     */
    @PostMapping("/updateWorkLogRemark")
    public DataResponse updateWorkLogRemark(@RequestParam(value="file", required = false) MultipartFile file,
                                            CustomerServiceWorkLogQO customerServiceWorkLogQO)
    {
        try{
            Boolean result = workLogService.updateWorkLogById(customerServiceWorkLogQO,file);
            if(result){
                return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
            }
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }catch(Exception e){
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }
}
